package com.example.user.http

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData

inline fun <E> LiveData<HhResult<E>>.handleResult(
    owner: LifecycleOwner, crossinline handler: HhResultHandler<E>.() -> Unit
){
    val responseHandler = HhResultHandler<E>().apply(handler)
    observe(owner){
        when(it){
            is HhResult.Success -> responseHandler.invokeSuccess(it.data!!)
//            is HhResult.Failure -> responseHandler.invokeFailure(it.message!!)
        }
    }
}